//
//  CGFloat+Ext.swift
//  iPhoneUTests
//
//  Created by Toj on 3/13/24.
//

import XCTest

final class CGFloat_Ext: XCTestCase {

    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func testExample() throws {
        print("-->UTests: start \n")
        testRandom()
        // testRandomUInt32()
        // testRandomCGFloat()
        
        print("-->UTests: end \n")
    }

    func testPerformanceExample() throws {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
}


extension CGFloat_Ext {
    
    func testRandom() {
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat.random(in: 0...1)
                print("-->UTests: random: \(r)")
            }
        }
    }

    func testRandomCGFloat() {
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat.random(in: 0...1)
                let g = CGFloat.random(in: 0...1)
                let b = CGFloat.random(in: 0...1)
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
        
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat.random(in: 0...1)
                let g = CGFloat.random(in: 0...1)
                let b = CGFloat.random(in: 0...1)
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
        
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat.random(in: 0...1)
                let g = CGFloat.random(in: 0...1)
                let b = CGFloat.random(in: 0...1)
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
    }
    
    func testRandomUInt32() {
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat(arc4random_uniform(256)) / 255.0
                let g = CGFloat(arc4random_uniform(256)) / 255.0
                let b = CGFloat(arc4random_uniform(256)) / 255.0
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
        
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat(arc4random_uniform(256)) / 255.0
                let g = CGFloat(arc4random_uniform(256)) / 255.0
                let b = CGFloat(arc4random_uniform(256)) / 255.0
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
        
        CM.absoluteDiffTimes {
            for _ in 0...100000 {
                let r = CGFloat(arc4random_uniform(256)) / 255.0
                let g = CGFloat(arc4random_uniform(256)) / 255.0
                let b = CGFloat(arc4random_uniform(256)) / 255.0
                _ = UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }
    }
}

